﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Application.App;
using Infrastructure.Error;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace FacadeApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class IMController : ControllerBase
    {
        public UserApplication userApplication { get; set; }
        public ILogger<IMController> _logger { get; set; }

        /// <summary>
        /// 通过IM账号获取头像和昵称
        /// </summary>
        /// <param name="IMUser"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<object> GetIMInfo(string IMUser)
        {
            try
            {
                var uid = User.Claims.First(i => i.Type == "ID").Value;

                var r = userApplication.GetIMInfo(IMUser);

                return this.Success(r);
            }
            catch (BizException ex)
            {
                return this.FailResult(ex.data, ex.Message);
            }
            catch (Exception ex)
            {
                _logger.LogException(ex);
                return this.FailResult(null, "系统繁忙，请稍后重试!");
            }
        }
    }
}
